Trò chơi Tic-Tac-Toe, game đánh caro full source code
- RoomInfo.cs
- PhotonNetwork /
- Plugins /
- Photon Unity Networking /
- Assets /
- project /
2 // <copyright file="RoomInfo.cs" company="Exit Games GmbH">
3 // Loadbalancing Framework for Photon - Copyright (C) 2011 Exit Games GmbH
4 // </copyright>
5 // <summary>
6 // This class resembles info about available rooms, as sent by the Master
7 // server's lobby. Consider all values as readonly.
8 // </summary>
9 // <author>developer@exitgames.com</author>
10 // ----------------------------------------------------------------------------
11
12 using System;
13 using ExitGames.Client.Photon;
14
15
16 /// <summary>
17 /// A simplified room with just the info required to list and join, used for the room listing in the lobby.
18 /// The properties are not settable (open, maxPlayers, etc).
19 /// </summary>
20 /// <remarks>
21 /// This class resembles info about available rooms, as sent by the Master server's lobby.
22 /// Consider all values as readonly. None are synced (only updated by events by server).
23 /// </remarks>
24 /// \ingroup publicApi
25 public class RoomInfo
26 {
27 /// <summary>Used internally in lobby, to mark rooms that are no longer listed.</summary>
28 public bool removedFromList { get; internal set; }
29
30 /// <summary>Backing field for property.</summary>
31 private Hashtable customPropertiesField = new Hashtable();
32
33 /// <summary>Backing field for property.</summary>
34 protected byte maxPlayersField = 0;
35
36 /// <summary>Backing field for property.</summary>
37 protected bool openField = true;
38
39 /// <summary>Backing field for property.</summary>
40 protected bool visibleField = true;
41
42 /// <summary>Backing field for property. False unless the GameProperty is set to true (else it's not sent).</summary>
43 protected bool autoCleanUpField = PhotonNetwork.autoCleanUpPlayerObjects;
44
45 /// <summary>Backing field for property.</summary>
46 protected string nameField;
47
48 /// <summary>Read-only "cache" of custom properties of a room. Set via Room.SetCustomProperties (not available for RoomInfo class!).</summary>
49 /// <remarks>All keys are string-typed and the values depend on the game/application.</remarks>
50 public Hashtable customProperties
51 {
52 get
53 {
54 return this.customPropertiesField;
55 }
56 }
57
58 /// <summary>The name of a room. Unique identifier (per Loadbalancing group) for a room/match.</summary>
59 public string name
60 {
61 get
62 {
63 return this.nameField;
64 }
65 }
66
67 /// <summary>
68 /// Only used internally in lobby, to display number of players in room (while you're not in).
69 /// </summary>
70 public int playerCount { get; private set; }
71
72 /// <summary>
73 /// State if the local client is already in the game or still going to join it on gameserver (in lobby always false).
74 /// </summary>
75 public bool isLocalClientInside { get; set; }
76
77 /// <summary>
78 /// Sets a limit of players to this room. This property is shown in lobby, too.
79 /// If the room is full (players count == maxplayers), joining this room will fail.
80 /// </summary>
81 /// <remarks>
82 /// As part of RoomInfo this can't be set.
83 /// As part of a Room (which the player joined), the setter will update the server and all clients.
84 /// </remarks>
85 public byte maxPlayers
86 {
87 get
88 {
89 return this.maxPlayersField;
90 }
91 }
92
93 /// <summary>
94 /// Defines if the room can be joined.
95 /// This does not affect listing in a lobby but joining the room will fail if not open.
96 /// If not open, the room is excluded from random matchmaking.
97 /// Due to racing conditions, found matches might become closed before they are joined.
98 /// Simply re-connect to master and find another.
99 /// Use property "IsVisible" to not list the room.
100 /// </summary>
101 /// <remarks>
102 /// As part of RoomInfo this can't be set.
103 /// As part of a Room (which the player joined), the setter will update the server and all clients.
104 /// </remarks>
105 public bool open
106 {
107 get
108 {
109 return this.openField;
110 }
111 }
112
113 /// <summary>
114 /// Defines if the room is listed in its lobby.
115 /// Rooms can be created invisible, or changed to invisible.
116 /// To change if a room can be joined, use property: open.
117 /// </summary>
118 /// <remarks>
119 /// As part of RoomInfo this can't be set.
120 /// As part of a Room (which the player joined), the setter will update the server and all clients.
121 /// </remarks>
122 public bool visible
123 {
124 get
125 {
126 return this.visibleField;
127 }
128 }
129
130 /// <summary>
131 /// Constructs a RoomInfo to be used in room listings in lobby.
132 /// </summary>
133 /// <param name="roomName"></param>
134 /// <param name="properties"></param>
135 protected internal RoomInfo(string roomName, Hashtable properties)
136 {
137 this.CacheProperties(properties);
138
139 this.nameField = roomName;
140 }
141
142 /// <summary>
143 /// Makes RoomInfo comparable (by name).
144 /// </summary>
145 public override bool Equals(object p)
146 {
147 Room pp = p as Room;
148 return (pp != null && this.nameField.Equals(pp.nameField));
149 }
150
151 /// <summary>
152 /// Accompanies Equals, using the name's HashCode as return.
153 /// </summary>
154 /// <returns></returns>
155 public override int GetHashCode()
156 {
157 return this.nameField.GetHashCode();
158 }
159
160 /// <summary>Simple printingin method.</summary>
161 /// <returns>Summary of this RoomInfo instance.</returns>
162 public override string ToString()
163 {
164 return string.Format("Room: '{0}' {1},{2} {4}/{3} players.", this.nameField, this.visibleField ? "visible" : "hidden", this.openField ? "open" : "closed", this.maxPlayersField, this.playerCount);
165 }
166
167 /// <summary>Simple printingin method.</summary>
168 /// <returns>Summary of this RoomInfo instance.</returns>
169 public string ToStringFull()
170 {
171 return string.Format("Room: '{0}' {1},{2} {4}/{3} players.\ncustomProps: {5}", this.nameField, this.visibleField ? "visible" : "hidden", this.openField ? "open" : "closed", this.maxPlayersField, this.playerCount, this.customPropertiesField.ToStringFull());
172 }
173
174 /// <summary>Copies "well known" properties to fields (isVisible, etc) and caches the custom properties (string-keys only) in a local hashtable.</summary>
175 /// <param name="propertiesToCache">New or updated properties to store in this RoomInfo.</param>
176 protected internal void CacheProperties(Hashtable propertiesToCache)
177 {
178 if (propertiesToCache == null || propertiesToCache.Count == 0 || this.customPropertiesField.Equals(propertiesToCache))
179 {
180 return;
181 }
182
183 // check of this game was removed from the list. in that case, we don't
184 // need to read any further properties
185 // list updates will remove this game from the game listing
186 if (propertiesToCache.ContainsKey(GameProperties.Removed))
187 {
188 this.removedFromList = (Boolean)propertiesToCache[GameProperties.Removed];
189 if (this.removedFromList)
190 {
191 return;
192 }
193 }
194
195 // fetch the "well known" properties of the room, if available
196 if (propertiesToCache.ContainsKey(GameProperties.MaxPlayers))
197 {
198 this.maxPlayersField = (byte)propertiesToCache[GameProperties.MaxPlayers];
199 }
200
201 if (propertiesToCache.ContainsKey(GameProperties.IsOpen))
202 {
203 this.openField = (bool)propertiesToCache[GameProperties.IsOpen];
204 }
205
206 if (propertiesToCache.ContainsKey(GameProperties.IsVisible))
207 {
208 this.visibleField = (bool)propertiesToCache[GameProperties.IsVisible];
209 }
210
211 if (propertiesToCache.ContainsKey(GameProperties.PlayerCount))
212 {
213 this.playerCount = (int)((byte)propertiesToCache[GameProperties.PlayerCount]);
214 }
215
216 if (propertiesToCache.ContainsKey(GameProperties.CleanupCacheOnLeave))
217 {
218 this.autoCleanUpField = (bool)propertiesToCache[GameProperties.CleanupCacheOnLeave];
219 }
220
221 //if (propertiesToCache.ContainsKey(GameProperties.PropsListedInLobby))
222 //{
223 // // could be cached but isn't useful
224 //}
225
226 // merge the custom properties (from your application) to the cache (only string-typed keys will be kept)
227 this.customPropertiesField.MergeStringKeys(propertiesToCache);
228 }
229 }
----------------------------------------------------------------------------
Loadbalancing Framework for Photon - Copyright (C) 2011 Exit Games GmbH
This class resembles info about available rooms, as sent by the Master
server's lobby. Consider all values as readonly.
----------------------------------------------------------------------------
A simplified room with just the info required to list and join, used for the room listing in the lobby.
The properties are not settable (open, maxPlayers, etc).
This class resembles info about available rooms, as sent by the Master server's lobby.
Consider all values as readonly. None are synced (only updated by events by server).
\ingroup publicApi
Only used internally in lobby, to display number of players in room (while you're not in).
State if the local client is already in the game or still going to join it on gameserver (in lobby always false).
Sets a limit of players to this room. This property is shown in lobby, too.
If the room is full (players count == maxplayers), joining this room will fail.
As part of RoomInfo this can't be set.
As part of a Room (which the player joined), the setter will update the server and all clients.
Defines if the room can be joined.
This does not affect listing in a lobby but joining the room will fail if not open.
If not open, the room is excluded from random matchmaking.
Due to racing conditions, found matches might become closed before they are joined.
Simply re-connect to master and find another.
Use property "IsVisible" to not list the room.
As part of RoomInfo this can't be set.
As part of a Room (which the player joined), the setter will update the server and all clients.
Defines if the room is listed in its lobby.
Rooms can be created invisible, or changed to invisible.
To change if a room can be joined, use property: open.
As part of RoomInfo this can't be set.
As part of a Room (which the player joined), the setter will update the server and all clients.
Constructs a RoomInfo to be used in room listings in lobby.
Makes RoomInfo comparable (by name).
Accompanies Equals, using the name's HashCode as return.
New or updated properties to store in this RoomInfo.
check of this game was removed from the list. in that case, we don't
need to read any further properties
list updates will remove this game from the game listing
fetch the "well known" properties of the room, if available
if (propertiesToCache.ContainsKey(GameProperties.PropsListedInLobby))
{
could be cached but isn't useful
}
merge the custom properties (from your application) to the cache (only string-typed keys will be kept)